/**
 * @file       godemool/iprinter.h
 * @brief      printer interface.
 * @author     ben "boin" bonoeil
 * @date       2015-02
 */

/* Copyright (c) 2007-2015, ben "boin" bonoeil */

#ifndef GODEMOOL_IPRINTER_H
#define GODEMOOL_IPRINTER_H

#include "godemool/decoder.h"
#include <ostream>

namespace boin { class IPrinter; }

class boin::IPrinter : public boin::Decoder {

public:
  IPrinter() : detail_usrcmd(true) {}

  virtual ~IPrinter() {}
  virtual void Open(const std::string &uri, const Hl2Demo::Header &hd) = 0;
  virtual void Close() = 0;
  virtual void Print(const Hl2Demo::Chunk * chk, const CodecType * obj);
  virtual void Print(const Hl2Demo::Header & hd);

protected:
  char tmp[256];
  bool detail_usrcmd; ///< set to print detailed usrcmd instead of raw-data.

  virtual void Print(const RawData & raw);
  virtual void Print(const CustomData & custom);
  virtual void Print(const ConCommand & cmd);
  virtual void Print(const UserCommand & cmd);
  virtual void Print(const StringTables & tables);
  virtual void Print(const std::vector<StringTable::String> & strings);
  virtual void Print(const DataTables & dtables);
  virtual void Print(const Messages & messages);
  virtual void Print(const google::protobuf::Message * msg, int idx = -1);

public:
  virtual void BegElt(const char * name) = 0;
  virtual void EndElt(const char * name) = 0;
  virtual void Attr(const char * name, const char * val) = 0;
  virtual void Str(const char * data) = 0;
  virtual void Data(const WalkData & data) = 0;

  const char * Fmt(bool b);
  const char * Fmt(int32_t i);
  const char * Fmt(uint32_t u);
  const char * Fmt(int64_t i);
  const char * Fmt(uint64_t u);
  const char * Fmt(float f);
  const char * Fmt(double d);

  void AttrIfTrue(const char * name, bool b) { if (b) Attr(name,true); }
  void Attr(const char * name, bool v)     { Attr(name,Fmt(v)); }
  void Attr(const char * name, int32_t v)  { Attr(name,Fmt(v)); }
  void Attr(const char * name, uint32_t v) { Attr(name,Fmt(v)); }
  void Attr(const char * name, int64_t v)  { Attr(name,Fmt(v)); }
  void Attr(const char * name, uint64_t v) { Attr(name,Fmt(v)); }
  void Attr(const char * name, float v)    { Attr(name,Fmt(v)); }
  void Attr(const char * name, double v)   { Attr(name,Fmt(v)); }
  void Attr(const char * name, const std::string & v) {
    Attr(name,v.c_str());
  }

  void Str(bool v)     { Str(Fmt(v)); }
  void Str(int32_t v)  { Str(Fmt(v)); }
  void Str(uint32_t v) { Str(Fmt(v)); }
  void Str(int64_t v)  { Str(Fmt(v)); }
  void Str(uint64_t v) { Str(Fmt(v)); }
  void Str(float v)    { Str(Fmt(v)); }
  void Str(double v)   { Str(Fmt(v)); }

};

#endif

/* Local Variables:  */
/* mode: c++         */
/* End:              */
